import Vue from 'vue'
import VueRouter from 'vue-router'
Vue.use(VueRouter);

import Login from '@/components/Login'
import Home from '@/components/Home'
import Welcome from '@/components/WelCome'
import Permission from '@/components/system/Permission'

import baseUrl from '@/plugins/baseUrl.js';

import LoanMoney from '@/components/load/LoanMoney'
import LoadSeniority from '@/components/load/LoadSeniority'
import LoadUserMessage from '@/components/load/LoadUserMessage'
import Loadmanager from  '@/components/aanager/Loadmanager'
import LoadDetailed from '@/components/aanager/LoadDetailed'

import PayBack from '@/components/payback/PayBack'
import PayBackUser from '@/components/payback/PayBackUser'
import Account from '@/components/aanager/Account'
import Accountmanager from '@/components/aanager/Accountmanager'


const routes = [
    {
        path: '/',
        redirect: '/login'
    },
    {
        path: '/login',
        component: Login
    },
    {
        path:'/home',
        component: Home,
        children:[
            {
                path:"/",
                component:Welcome
            },
            {
                path:"/permission",
                component:Permission
            },
            {
                path:"/user",
                component:LoadSeniority
            },
            {
                path:"/userMessage/:umId",
                component:LoadUserMessage
            },
            {
                path:"/loadmanager",
                component:Loadmanager
            },
            {
                path:"/load",
                component:LoanMoney
            },
            {
                path:"/loadDetailed/:lId",
                component:LoadDetailed
            },
            {
                path:"/payBack",
                component:PayBack
            },
            {
                path:"/loadUser",
                component:PayBackUser
            },
            {
                path:"/account",
                component:Account
            },
            {
                path:"/accountmanager/:aUid",
                component:Accountmanager
            }
        ]
    }
]
const router = new VueRouter({
    mode: 'history',
    routes
})

import MessageBox from 'element-ui';

//设置路由守卫
router.beforeEach((to,from,next)=>{
    if (to.path=="/" || to.path=="/login"){
        next();
    } else {
        let uCode = sessionStorage.getItem("token");
        if (uCode){
            next();
        } else {
            MessageBox.Message.warning("请先登录....");
            next("/")
        }
    }
});
export default router
